//
//  ResponseModel.swift
//
//  Created by Ink on 2024/6/21.
//  Copyright © 2024 ZM. All rights reserved.
//

import UIKit
import Codextended
import BetterCodable


public enum ResponseType: Int, Codable {
    
    case OK = 0
    /// 登录过期
    case LoginPast = 401
    /// 金币不足
    case InsufficientBalance = 403
    
    case forbidden = 10002
    
    case Error = -1
        
    public enum DefaultError: DefaultCodableStrategy {
        
        public static var defaultValue: ResponseType { .Error }
    }
    
    public static let noAutoToastType:[ResponseType] = [.OK]
    
}

public struct KJSONNull: CodableModel {}

public struct ResponseModel<C:Codable> : CodableModel {
    public var code: Int?
    public var msg: String?
    public var data: C?
    
    public var responseType: ResponseType {
        return ResponseType(rawValue: code ?? -1) ?? .Error
    }
}

public protocol ItemsModelProtocol {
    var pageIndex: Int? { get }
    var hasMore: Bool? { get }
}

public struct ItemsModel<C:Codable>: CodableModel, ItemsModelProtocol {
    
    public var items: [C]?
    public var pageIndex,pageSize, totalPages,totalItems: Int?
    
    public var hasMore: Bool? { (pageIndex ?? 0) < (totalPages ?? 0) && items?.isNotEmpty == true }
//    public var current: Int? { pageIndex  }
//    public var total: Int? { totalPages }
//    public var records: [C]? { items }
}
